package com.xr.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.sunnyday.constant.MessageConstant;
import com.xr.sunnyday.entity.PageResult;
import com.xr.sunnyday.entity.QueryPageBean;
import com.xr.sunnyday.entity.Result;
import com.xr.sunnyday.pojo.CheckGroup;
import com.xr.sunnyday.service.CheckGroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkGroup")
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;

    @PostMapping("/findByCondition")
    public Result findByCondition(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkGroupService.findByCondition(queryPageBean);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS,pageResult);
    }

    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds){
        checkGroupService.add(checkGroup,checkitemIds);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    @PostMapping("/findByCheckGroupId")
    public Result findByCheckGroupId(int checkGroupId){
        CheckGroup checkGroup= checkGroupService.findByCheckGroupId(checkGroupId);
        return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    @PostMapping("/findCheckItemIdByCheckGroupId")
    public Result findCheckItemIdByCheckGroupId(int checkGroupId){
        List<Integer> checkItemIds= checkGroupService.findCheckItemIdByCheckGroupId(checkGroupId);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItemIds);
    }


    @PostMapping("/update")
    public Result update(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds){
        checkGroupService.update(checkGroup,checkitemIds);
        return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
    }


    @PostMapping("/deleteById")
    public Result deleteById(int id){
        checkGroupService.deleteById(id);
        return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }


    @GetMapping("/queryAll")
    public Result queryAll(){
        List<CheckGroup> groupList= checkGroupService.queryAll();
        return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,groupList);
    }

}
